﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：马毅
    //
    // 文件名：DrugBySelection.cs
    // 文件功能描述：查询本企业所以的产品（自己中标的产品）
    // 创建标识：马毅2009-05-12
    //
    // 修改标识： 
    // 修改描述： 被医疗机构选中作为默认配送的产品
    //
    // 修改标识： 
    // 修改描述： 
    //
    // 审核人： 
    // 审核时间： 
    // 审核说明： 
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.IBLL;
using HZ.Common;
using System.Collections;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;
using HZ.DrugTrade.BLLFactory;
namespace HZ.DrugTrade.Web.Enterprise.RelationQuery
{
    public partial class DrugBySelection : BasePage
    {
        IList<HZ.DrugTrade.Model.Company> CompanyList;
        IBLL_Company iBLL_Company = Factory.BLL_Company();
        IBLL_HospitalProcureCatalog ihp = Factory.BLL_HospitalProcureCatalog();
        public DrugBySelection()
        {
            this.ModuleNo = Module.配送区域管理.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //BindCbo_CompanySC();//企业名称改输入
                BindCbxProjectName();
                BindArea();//绑定地区
                BindgvwProcureCatalog();
                //BindcbxCompanyname_Ps();//企业名称改输入
            }
        }
        /// <summary>
        /// 绑定地区2009-11-20
        /// </summary>
        private void BindArea()
        {

            IBLL_Area iBLL_Area = Factory.BLL_Area();
            string AreaID = CurrentAccount.GetCurrentDeployArea().AreaID;
            IList<Area> list = iBLL_Area.GetAllCity(AreaID);
            this.ddlArea.DataSource = list;
            this.ddlArea.DataTextField = "AreaName";
            this.ddlArea.DataValueField = "AreaID";
            this.ddlArea.DataBind();
            ListItem item = new ListItem();
            item.Text = Constants.ALL_ITEM_TEXT;
            item.Value = Constants.ALL_ITEM_VALUE;
            this.ddlArea.Items.Insert(0, item);
        }
        /// <summary>
        /// 绑定项目
        /// </summary>
        private void BindCbxProjectName()
        {
            IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
            IList<ProcurementProject> projectList = ipb.GetAllProcurementProject();
            cbxProjectName.DataSource = projectList;
            cbxProjectName.DataTextField = "ProjectName";
            cbxProjectName.DataValueField = "ProjectID";
            cbxProjectName.DataBind();
            ListItem item = new ListItem();
            item.Text = Constants.ALL_ITEM_TEXT;
            item.Value = Constants.ALL_ITEM_VALUE;
            cbxProjectName.Items.Insert(0, item);
        }
        /// <summary>
        /// 绑定生产企业
        /// 已不使用 by ligang 20090621
        /// </summary>
        private void BindCbo_CompanySC()
        {
            //HZ.DrugTrade.Model.Enum.EnumCompanyType EnumCompanyType;
            HZ.DrugTrade.Model.Query.Company qCompany = new HZ.DrugTrade.Model.Query.Company();
            qCompany.CompanyType = EnumCompanyType.生产企业;
            int italRecourd;
            CompanyList = iBLL_Company.GetCompanyByWhere(qCompany, 1, 10, out italRecourd);
            HZ.DrugTrade.Model.Company Company = new Company();
            ArrayList arrCompanyList = new ArrayList();
            Company = new Company();
            Company.CompanyID = null;
            Company.CompanyName = "请选择...";
            arrCompanyList.Add(Company);
            for (int i = 0; i < CompanyList.Count; i++)
            {
                Company = new Company();
                Company.CompanyID = CompanyList[i].CompanyID;
                Company.CompanyName = CompanyList[i].CompanyName;
                arrCompanyList.Add(Company);
            }

        }
        /// <summary>
        /// 配送企业绑定
        /// 已不使用 by ligang 20090621
        /// </summary>
        private void BindcbxCompanyname_Ps()
        {
            HZ.DrugTrade.Model.Query.Company qCompany = new HZ.DrugTrade.Model.Query.Company();
            qCompany.CompanyType = EnumCompanyType.配送企业;
            int italRecourd;
            CompanyList = iBLL_Company.GetCompanyByWhere(qCompany, 1, 10, out italRecourd);
            HZ.DrugTrade.Model.Company Company = new Company();
            ArrayList arrCompanyList = new ArrayList();
            Company = new Company();
            Company.CompanyID = null;
            Company.CompanyName = "请选择...";
            arrCompanyList.Add(Company);
            for (int i = 0; i < CompanyList.Count; i++)
            {
                Company = new Company();
                Company.CompanyID = CompanyList[i].CompanyID;
                Company.CompanyName = CompanyList[i].CompanyName;
                arrCompanyList.Add(Company);
            }

        }
        /// <summary>
        /// 绑定grivedate
        /// </summary>
        /// <param name="_bsingle"> 是否按简单查询 true 简单  false 高级查询</param>
        private void BindgvwProcureCatalog()
        {
            Model.Query.HospitalProcureCatalog qHospitalCatalog = new HZ.DrugTrade.Model.Query.HospitalProcureCatalog();
            qHospitalCatalog.GoodsName = txtGoodsName.Text.Trim();
            qHospitalCatalog.Material = txtMaterial.Text.Trim();
            qHospitalCatalog.Outlookc = txtOutlookc.Text.Trim();
            qHospitalCatalog.Companyid_Ps = CurrentAccount.GetUser().Org.OrgID;
            qHospitalCatalog.Companyname_Tb = txtCompanyName_TB.Text.Trim();//企业名称不用下拉框，改输入
            qHospitalCatalog.Companyname_Sc = txtCompanyName_Sc.Text.Trim();//企业名称不用下拉框，改输入
            qHospitalCatalog.ProjectName = cbxProjectName.SelectedIndex == 0 ? "" : cbxProjectName.SelectedItem.Text.Trim();
            qHospitalCatalog.Unit = txtUnit.Text.Trim();
            qHospitalCatalog.PinyinCode = this.txtpinyincode.Text.Trim();
            qHospitalCatalog.ProjectID = this.ddlProjectid.SelectedValue;
            //qHospitalCatalog.PinyinCode = this.txtPinyinCode.Text.Trim().ToUpper();
            qHospitalCatalog.HospitalName = txtHospitalName.Text.Trim();
            qHospitalCatalog.AreaID = ddlArea.SelectedIndex == 0 ? "" : ddlArea.SelectedValue.ToString();
            qHospitalCatalog.IsUsing = true;
            qHospitalCatalog.SortFields = " GoodsName asc,ProcureCataLogID,areaid,companyid_ps ";

            int totalRecord = 0;

            IList<Model.View.HospitalProcureCatalog> hosiptalCatalogList = ihp.GetHospitalProcureCatalog(qHospitalCatalog, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalRecord);
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            AspNetPager1.RecordCount = totalRecord;

            gvwProcureCatalog.DataSource = hosiptalCatalogList;
            gvwProcureCatalog.DataBind();

            if (gvwProcureCatalog.Rows.Count <= 0)
            {
                btnExport.Visible = false;
            }

        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindgvwProcureCatalog();
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            BindgvwProcureCatalog();
        }
        /// <summary>
        /// 简单查询与高级查询的转换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbnSwitch_Click(object sender, EventArgs e)
        {
            if (lbnSwitch.CommandArgument == "simple")
            {
                ltlAdvance.Text = "";
                lbnSwitch.CommandArgument = "advance";
                lbnSwitch.Text = "简单查询";
            }
            else
            {
                ltlAdvance.Text = "<tbody id='advance' style='display:none'>";
                lbnSwitch.CommandArgument = "simple";
                lbnSwitch.Text = "高级查询";

                //清空数据

                cbxProjectName.SelectedIndex = 0;
                txtUnit.Text = "";
                //txtProcurePrice.Text = "";
                //txtGoodsName.Text="";

                //txtOperateTimeBegin.Text = "";
                //txtOperateTimeEnd.Text = "";
                //dtProcureBeginTimeBegin.Text = "";
                //dtProcureBeginTimeEnd.Text = "";
                //dtProcureEndTimeBegin.Text = "";
                //dtProcureEndTimeEnd.Text = "";

            }
        }

        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            HZ.DrugTrade.Model.Query.HospitalProcureCatalog qHospitalCatalog = new HZ.DrugTrade.Model.Query.HospitalProcureCatalog();

            qHospitalCatalog.GoodsName = txtGoodsName.Text.Trim();
            qHospitalCatalog.Material = txtMaterial.Text.Trim();
            qHospitalCatalog.Outlookc = txtOutlookc.Text.Trim();
            qHospitalCatalog.Companyid_Ps = CurrentAccount.GetUser().Org.OrgID;
            qHospitalCatalog.Companyname_Tb = txtCompanyName_TB.Text.Trim();//企业名称不用下拉框，改输入
            qHospitalCatalog.Companyname_Sc = txtCompanyName_Sc.Text.Trim();//企业名称不用下拉框，改输入
            qHospitalCatalog.ProjectName = cbxProjectName.SelectedIndex == 0 ? "" : cbxProjectName.SelectedItem.Text.Trim();
            qHospitalCatalog.Unit = txtUnit.Text.Trim();
            qHospitalCatalog.ProjectID = this.ddlProjectid.SelectedValue;
            //qHospitalCatalog.PinyinCode = this.txtPinyinCode.Text.Trim().ToUpper();
            qHospitalCatalog.PinyinCode = this.txtpinyincode.Text.Trim();
            qHospitalCatalog.HospitalName = this.txtHospitalName.Text.Trim();
            qHospitalCatalog.SortFields = " GoodsName asc,goodsid ";

            int totalRecord = 0;
            IBLL_Distribution ipb = Factory.BLL_Distribution();
            IList<Model.View.HospitalProcureCatalog> hosiptalCatalogList = ihp.GetHospitalProcureCatalog(qHospitalCatalog, 1, 0, out totalRecord);

            DataTable dt = HZ.Data.ModelConvert.GetDataTableFromModel(hosiptalCatalogList);
            HZ.Excel.ExcelHelper.ExportDataForWeb(dt, gvwProcureCatalog);
        }

        protected void gvwProcureCatalog_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                if (ddlProjectid.SelectedItem.Value == "0002")
                {
                    e.Row.Cells[e.Row.Cells.Count - 2].Text = "自主报价";
                }
                else
                {
                    e.Row.Cells[e.Row.Cells.Count - 2].Text = "采购限价";
                }
            }
        }
    }
}
